package com.lianbang.pharmacy.module.user

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

import com.lianbang.pharmacy.R
import cn.ubest.mvvmcore.base.BaseActivity
import cn.ubest.mvvmcore.base.BaseListActivity
import cn.ubest.mvvmcore.databinding.IncludeToolbarListWithRefreshBinding
import cn.ubest.mvvmcore.interfaces.IEmptyView
import cn.ubest.mvvmcore.utils.DoubleClickHelper
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lianbang.pharmacy.adapter.CouponCenterListAdapter
import com.lianbang.pharmacy.adapter.MyCouponListAdapter
import com.lianbang.pharmacy.bean.CouponListBean
import com.lianbang.pharmacy.databinding.ActivityMyScoreBinding
import com.lianbang.pharmacy.util.EmptyViewUtils
import com.lianbang.pharmacy.vm.CouponVM
import com.lianbang.pharmacy.vm.MainVM
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import kotlinx.android.synthetic.main.activity_my_score.*

class MyCouponListActivity :
    BaseListActivity<CouponVM, IncludeToolbarListWithRefreshBinding, CouponListBean>(), IEmptyView {

    companion object {
        fun start(context: Context?) {
            context?.also {
                val starter = Intent(it, MyCouponListActivity::class.java)
                if (it !is Activity) {
                    starter.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                }
                it.startActivity(starter)
            }
        }
    }

    override fun initLayout(): Int {
        return R.layout.include_toolbar_list_with_refresh

    }

    override fun setToolbarTitle(): String? {
        return "我的优惠券"
    }

    override fun initData(intent: Intent) {
        super.initData(intent)
    }

    override fun initView() {
        super.initView()
    }

    override fun loadData() {
        mViewModel.refreshData()
    }

    override fun initAdapter(): BaseQuickAdapter<CouponListBean, *> {
        return MyCouponListAdapter()
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.menu_my_coupon, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when (item.itemId) {
            R.id.btn_more -> CouponCenterActivity.start(this)
        }
        return super.onOptionsItemSelected(item)
    }

    override fun getEmptyView(): View {
        return EmptyViewUtils.getEmptyView(this, R.drawable.empty_my_coupon, "暂无优惠卷～")
    }
}
